import subprocess

class CommandLineHandler(object):
    def __init__(self, IP, password):
        self.IP = IP
        self.password = password

    def transfer_file(self, original_filepath, new_filepath):
        try:
            subprocess.check_call(["sshpass", 
                                    "-p", self.password, 
                                    "scp", 
                                    "nao@{ip}:{path}".format(ip=self.IP, path = original_filepath), new_filepath])
            
            return True
        
        except subprocess.CalledProcessError:
            print("Something went horribly wrong!")
            return False

        
    def convert_file_to_16kHz(self, file_path, converted_file_path):
        try:
            subprocess.check_call(["sox", 
                                    file_path, 
                                    "-c",  "1", 
                                    "-r", "16000",
                                    converted_file_path])
            
            return True
        
        except subprocess.CalledProcessError:
            print("Could not convert audio to 16kHz")
            return False


if __name__ == "__main__":
    CLH = CommandLineHandler("192.168.1.33", "nao")
    #CLH.transfer_file("/home/nao/speed_test.wav", "/home/pussinenkumara")
    CLH.convert_file_to_16kHz("/home/jerry/audio_files/audio_test.wav", "/home/jerry/audio_files/audio_converted.wav")
    